/*
 *  Copyright 2009 Utkin Dmitry
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
 
/* 
 *  This file is part of the WSF Staff project.
 *  Please, visit http://code.google.com/p/staff for more information.
 */

// This file generated by staff_codegen
// Service Implementation

#include <staff/common/Exception.h>
#include <staff/common/Exception.h>
#include <staff/security/Sessions.h>
#include <staff/component/SessionManager.h>
#include "LoginImpl.h"

namespace staff
{

  LoginImpl::~LoginImpl()
  {
  }

  std::string LoginImpl::LoginUser(const std::string& sUserName, const std::string& sPassword)
  {
    std::string tResult;

    STAFF_ASSERT(IService::GetSessionId() == staff::security::Sessions::sNobodySessionId,
      "Cannot login from non-nobody session");

    staff::SessionManager::Inst().Login(sUserName, sPassword, tResult);

    return tResult;  // result
  }

  std::string LoginImpl::OpenSession(const std::string& sUserName, const std::string& sPassword, bool bCloseExisting)
  {
    std::string tResult;

    STAFF_ASSERT(IService::GetSessionId() == staff::security::Sessions::sNobodySessionId,
      "Cannot login from non-nobody session");

    staff::SessionManager::Inst().Open(sUserName, sPassword, bCloseExisting, tResult);

    return tResult;  // result
  }

  void LoginImpl::Logout()
  {
    staff::SessionManager::Inst().Close(IService::GetSessionId());
  }

  void LoginImpl::KeepAliveSession()
  {
    staff::SessionManager::Inst().Keepalive(IService::GetSessionId());
  }

  int LoginImpl::GetUserId()
  {
    int tResult;

    staff::security::Sessions::Inst().GetUserId(IService::GetSessionId(), tResult);

    return tResult;  // result
  }

  std::string LoginImpl::GetUserName()
  {
    std::string tResult;

    staff::security::Sessions::Inst().GetUserName(IService::GetSessionId(), tResult);

    return tResult;  // result
  }

  std::string LoginImpl::GetUserDescription()
  {
    std::string tResult;

    staff::security::Sessions::Inst().GetUserDescription(IService::GetSessionId(), tResult);

    return tResult;  // result
  }

  int LoginImpl::GetSessionExpiration() const
  {
    return staff::security::Sessions::Inst().GetExpiration();
  }

  bool LoginImpl::ValidateSession()
  {
    return staff::security::Sessions::Inst().Validate(IService::GetSessionId());
  }

}

